package com.cmc.cloud.cmclink.doc.controller.admin.so;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.SoCargoConvert;
import com.cmc.cloud.cmclink.doc.entity.SoCargoDO;
import com.cmc.cloud.cmclink.doc.service.so.SoCargoService;
import com.cmc.cloud.cmclink.doc.vo.sovo.socargovo.SoCargoPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.sovo.socargovo.SoCargoRespVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 订舱货物信息前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 订舱货物信息")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/so-cargo")
public class SoCargoController {

    @Resource
    private SoCargoService soCargoService;


    @Operation(summary = "获得订舱货物信息")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('doc:so-cargo:query')")
    public CommonResult<SoCargoRespVO> getSoCargo(@PathVariable("id") Long id) {
        SoCargoDO soCargo = soCargoService.getSoCargo(id);
        return CommonResult.success(SoCargoConvert.INSTANCE.convert(soCargo));
    }

    @Operation(summary = "获得订舱货物信息列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('doc:so-cargo:query')")
    public CommonResult<List<SoCargoRespVO>> getSoCargoList(@RequestParam("ids") Collection<Long> ids) {
        List<SoCargoDO> list = soCargoService.getSoCargoList(ids);
        return CommonResult.success(SoCargoConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得订舱货物信息分页")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPermission('doc:so-cargo:query')")
    public CommonResult<PageResult<SoCargoRespVO>> getSoCargoPage(@Valid SoCargoPageReqVO pageVO) {
        PageResult<SoCargoDO> pageResult = soCargoService.getSoCargoPage(pageVO);
        List<SoCargoRespVO> results = SoCargoConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
